package com.nf.health.app.adapter;

import android.content.Context;
import android.media.Image;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.models.Account;
import com.nf.health.app.models.IntegrationVo;
import com.nf.health.app.utils.ImageLoaderUtils;

import java.util.List;

/**
 * 积分列表适配器
 * @author jiax
 *
 */
public class MyIntegrationListAdapter extends BaseAdapter {

	private List<IntegrationVo> accounts;
	private Context context;


	public MyIntegrationListAdapter(List<IntegrationVo> accounts,Context context) {
		this.accounts = accounts;
		this.context = context;

	}

	@Override
	public int getCount() {
		if(accounts != null){
			return accounts.size();
		}
		return 0;
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder = ViewHolder.get(parent, convertView, R.layout.item_integration_list, position);
		IntegrationVo account = accounts.get(position);

		ImageView ic_integration = holder.getView(R.id.ic_integration);
		TextView tv_integration_wwc = holder.getView(R.id.tv_integration_wwc);
		TextView tv_integration_ywc = holder.getView(R.id.tv_integration_ywc);

		holder.setText(R.id.tv_integration_name, account.getName());
		holder.setText(R.id.tv_integration_score, "+"+account.getScore()+"分");


		//判断是否完成状态
		if(account.getState().equals("0")){
			tv_integration_wwc.setVisibility(View.VISIBLE);
			tv_integration_ywc.setVisibility(View.GONE);
		}else if(account.getState().equals("1")){
			tv_integration_wwc.setVisibility(View.GONE);
			tv_integration_ywc.setVisibility(View.VISIBLE);
		}else{
			tv_integration_wwc.setText("部分完成");
			tv_integration_wwc.setVisibility(View.VISIBLE);
			tv_integration_ywc.setVisibility(View.GONE);
		}

		if(account.getType().equals("1")){
			ic_integration.setImageResource(R.drawable.ic_integration_1);
		}else if(account.getType().equals("2")){
			ic_integration.setImageResource(R.drawable.ic_integration_2);
		}else if(account.getType().equals("3")){
			ic_integration.setImageResource(R.drawable.ic_integration_3);
		}else if(account.getType().equals("4")){
			ic_integration.setImageResource(R.drawable.ic_integration_4);
		}else if(account.getType().equals("5")){
			ic_integration.setImageResource(R.drawable.ic_integration_5);
		}else if(account.getType().equals("6")){
			ic_integration.setImageResource(R.drawable.ic_integration_6);
		}else if(account.getType().equals("7")){
			ic_integration.setImageResource(R.drawable.ic_integration_7);
		}else{
			ic_integration.setImageResource(R.drawable.ic_integration_7);

		}
		return holder.getConvertView();
	}
}
